package com.daiqile.myinterest.activity;

import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.daiqile.myinterest.R;
import com.daiqile.myinterest.adapter.AllbankcardAdapter;
import com.daiqile.myinterest.model.AllBankcardList;
import com.daiqile.myinterest.utils.CommonItemDecoration;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private CoordinatorLayout coordinatorLayout;
    private AllbankcardAdapter adapter;
    private List<AllBankcardList.ListBean> ListBean = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
        RecyclerView recyclerView = (RecyclerView)findViewById(R.id.allbankcard_recycle_view);
       coordinatorLayout = (CoordinatorLayout)findViewById(R.id.activity_main);
        SmartRefreshLayout refreshLayout = (SmartRefreshLayout)findViewById(R.id.smart_refresh);
        CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout)findViewById(R.id.collapsing);
        setSupportActionBar(toolbar);
        ActionBar actionbar = getSupportActionBar();
        if (actionbar != null){
            actionbar.setDisplayHomeAsUpEnabled(true);
        }
        collapsingToolbarLayout.setTitle("ABC");
//        collapsingToolbarLayout.setCollapsedTitleTextColor(Color.YELLOW);
//        collapsingToolbarLayout.setExpandedTitleColor(Color.WHITE);

        initList();
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.addItemDecoration(new CommonItemDecoration(10,10,10,0));
        adapter =  new AllbankcardAdapter(ListBean);
        recyclerView.setAdapter(adapter);
        refreshLayout.setRefreshHeader(new ClassicsHeader(this));//设置头部
        refreshLayout.setRefreshFooter(new ClassicsFooter(this));//尾
        //监听
        refreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                refreshlayout.finishLoadmore(2000);
            }
        });
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                refreshlayout.finishRefresh(2000);

            }
        });
    }

    private void initList() {
        for(int i = 0;i < 10 ;i ++){
            AllBankcardList.ListBean id = new AllBankcardList.ListBean();
            ListBean.add(id);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.toolbar,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                return true;
            case R.id.one:
                coordinatorLayout.setBackgroundResource(R.drawable.titlepic);
                return true;
            case R.id.two:
                coordinatorLayout.setBackgroundResource(R.drawable.background);
                return true;

        }
        return super.onOptionsItemSelected(item);
    }

}
